﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer
{
    public abstract class Repository<T> where T : class
    {
        protected readonly HRSEntities _context = new HRSEntities();

        public IQueryable<T> GetAll()
        {
            return _context.CreateObjectSet<T>();
        }

        public void Add(T entity)
        {
            _context.CreateObjectSet<T>().AddObject(entity);
        }

        public void Delete(T entity)
        {
            _context.CreateObjectSet<T>().DeleteObject(entity);
        }

        public void DeleteAll()
        {
            foreach (T entity in _context.CreateObjectSet<T>())
            {
                _context.DeleteObject(entity);
            }
        }

        public void Commit()
        {
            _context.SaveChanges();
        }

        public void Dispose()
        {
            _context.Dispose();
        }

        public abstract T FindById(int id);
    }
}
